﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Black.Jack
{
    public class Deck
    {
        Random randomNumber = new Random();

        
	    int[] cards = new int[52];
	    int card = 0;

	    public Deck()
	    {
            for( int suit = 0; suit < 4; ++suit )
		    {
			    for( int card = 0; card < 13; ++card )
			    {
				    int index = ( suit * 13 ) + card;

				    if( card < 10 )
					    cards[index] = card + 1;
				    else if( card >= 10 )
					    cards[index] = 10;
			    }
		    }	
	    }

	    public void PrintDeck()
	    {
		    for(int suit = 0; suit < 4; ++suit )
		    {
			    for( int card = 0; card < 13; ++card )
			    {
				    int index = ( suit * 13 ) + card;
				    Console.Out.Write( cards[index] + " ");
			    }
			    Console.Out.WriteLine();
		    }
	    }

	    public void Shuffle()
	    {
		    int temp, random;
		    for( int i = 0; i < 52; i++ )
		    {
			    random = randomNumber.Next(52);
			    temp = cards[i];
			    cards[i] = cards[random];
			    cards[random] = temp;
		    }
	    }

	    public int DealCard()
	    {
            if (card < 52)
            {
                return cards[card++];
                
            }
            else
            {
                Shuffle();
                card = 1;
                return cards[0];
            }
	    }
    }
}
